<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
    <title>场所码绑定</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <script src="./layui/layui.js"></script>
    <script src="./jquery/jquery.min.js"></script>
    <style>
        body {
            padding-top: 40px;
        }

        .layui-btn {
            padding: 0px 30px;
        }
    </style>
</head>

<body>
    <div class="layui-form-item">
        <label class="layui-form-label">场所名称</label>
        <div class="layui-input-inline">
            <input type="text" name="text" required lay-verify="required" placeholder="请输入场所码显示名称" autocomplete="off"
                class="layui-input layui-name">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required" placeholder="请输入绑定场所密码" autocomplete="off"
                class="layui-input layui-pas">
        </div>
    </div>
    <div style="text-align: center;">
        <button type="button" class="layui-btn">绑定</button>
    </div>
    <script>
        function getQueryVariable(variable) {
            var query = decodeURI(window.location.search.substring(1))
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return (false);
        }
        layui.use(['layer', 'jquery'], function () {
            var layer = layui.layer,
                $ = layui.jquery;
           $('.layui-btn').click(function() {
                $.ajax({
                    url: "http://ymt.city1000.cn/test/bangding",
                    type: "post",
                    data: {
                        name: $('.layui-name').val(),
                        secret: $('.layui-pas').val(),
                        wxcode: getQueryVariable('code')
                    },
                    success: function (res) {
                        console.log(res)
                        if (res.code == 1) {
                            layer.alert(res.msg,function(){
                              window.location.href="http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url=http://hesuan.city1000.cn/bind/binds.html&data=123"
                            });
                          
                            
                        } else if (res.code == 0) {
                            // 成功
                            layer.alert(res.msg,function(){
                              window.location.href="http://hesuan.city1000.cn/public/code.html"
                            });
                        }
                        // $('layui-input-select').html(``)
                    },
                    error: function (err) {
                        console.log(err)
                    }
                })
            })
            
        })
    </script>
</body>

</html>